package cn.qvtu.game.model;

import cn.qvtu.game.util.StaticValue;
import cn.qvtu.game.model.Person;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public class BackGround
{
    //显示的场景图片
    private BufferedImage showBgImage = null;
    //序号
    private int sort;
    //下一场景序号
    private int nextSort;
    //敌人
    private List<Enemy> allEnemy = new ArrayList<Enemy>();

    private Person person;

    private Tools tools;
    public void setPerson(Person person)
    {
        this.person=person;
    }
    public Person getPerson()
    {
        return this.person;
    }
    //道具
    private List<Tools> allTools=new ArrayList<Tools>();
    //血量
    private int hp=100;
    public void setTools(Tools tools)
    {
        this.tools=tools;
    }
    public BackGround(int sort)
    {
        this.sort=sort;
        create();
    }
    /**
     * 根据sort选择场景
     */
    public void create()
    {
        if (this.sort == 1)
        {
            this.showBgImage = StaticValue.bg01;
            this.allEnemy.add(new Enemy(600,145,this));
            this.allEnemy.add(new Enemy(400,145,this));
            this.nextSort = 2;
        }
        else if (this.sort == 2)
        {
            this.showBgImage = StaticValue.bg02;
            this.allEnemy.add(new Enemy(400,145,this));
            this.allEnemy.add(new Enemy(200,145,this));
            this.nextSort = 3;
        }
        else if (this.sort == 3)
        {
            this.showBgImage = StaticValue.bg03;
            this.allEnemy.add(new Enemy(400,145,this));
            this.allEnemy.add(new Enemy(200,145,this));
            this.allEnemy.add(new Enemy(600,145,this));
            this.nextSort = 4;
        }
        else if (this.sort == 4)
        {
            this.showBgImage = StaticValue.bg04;
            this.allEnemy.add(new Enemy(600,145,this));
            this.allEnemy.add(new Enemy(400,145,this));
            this.allEnemy.add(new Enemy(300,145,this));
            this.allEnemy.add(new Enemy(100,145,this));
        }
    }
    /**
     * 是否有下一场景
     */
    public boolean hasNext()
    {
        return nextSort != 0;
    }
    /**
     * 创建下一个场景
     */
    public BackGround next()
    {
        BackGround background=new BackGround(nextSort);
        background.setPerson(person);
        background.setHp(getHp());//切换场景血量不刷新
        return background;
    }
    public void setHp(int hp)
    {
        this.hp = hp;
    }
    /**
     * 是否可以通过
     */
    public boolean isPass(Person person)
    {
        if (person.getX()>=750)
        {
            return true;
        }
        return false;
    }
    public BufferedImage getShowBgImage()
    {
        return showBgImage;
    }
    public void setShowBgImage(BufferedImage showBgImage)
    {
        this.showBgImage = showBgImage;
    }

    public List<Enemy> getAllEnemy()
    {
        return this.allEnemy;
    }
    public List<Tools> getAllTools()
    {
        return this.allTools;
    }
    public void addTools(int x,int y)
    {
        Tools tl = new Tools(x, y, this);
        this.allTools.add(tl);
    }

    public int getHp()
    {
        if(person.getBackGround().hp<=10000)
        {
            return this.hp;
        }
        return 10000;
    }

}
